import React, { useState, useEffect } from 'react'
// 引入store
import store from '../redux/store'
// 引入actionCreator
import { setM } from '../redux/actions'
export default function Ls() {
  const [x, setX] = useState('x')
  useEffect(() => {
    // 监听redux数据的变化,当redux数据发生变化,则让当前组件更新
    store.subscribe(() => {
      console.log('redux数据发生变化了')
      setX((x) => {
        return x + 'x'
      })
    })
  }, [])
  return (
    <div>
      <input
        type="text"
        onKeyUp={(e) => {
          if (e.keyCode === 13) {
            store.dispatch(setM(e.target.value))
          }
        }}
      />
      <p>{store.getState().ls.msg}</p>
    </div>
  )
}
